package com.csi.controller;

import com.csi.domain.Result;
import com.csi.utils.ReturnResults;
import com.csi.utils.SMS;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sms")
public class SMSController {

    /**
     * 发送验证码
     * @param phone
     * @return
     * @throws Exception
     */
    @PostMapping("/code")
    public Object getCode(@RequestParam("phone") String phone) throws Exception {
        int number = SMS.getCode(phone);

        if (number > 0) {
            return new Result("发送成功",ReturnResults.ACCESS_SUCCESS,number);
        }
        return new Result("发送失败",ReturnResults.ACCESS_FAILED);
    }

    /**
     * 向指定手机号发送用户名、密码
     * @param phone
     * @param username
     * @param password
     * @throws Exception
     */
    @PostMapping("/userInfo")
    public void getUserInfo(@RequestParam("phone") String phone,
                              @RequestParam("username") String username,
                              @RequestParam("password") String password) throws Exception {
        SMS.userInfo(phone, username, password);
    }
}
